import { Effect, ImmerReducer, Reducer, Subscription } from 'umi';

interface userInfo {
}

export interface IndexModelState {
  userInfo: userInfo
}

export interface IndexModelType {
  namespace: 'user';
  state: IndexModelState;
  effects: {
    query: Effect;
  };
  reducers: {
    // save: Reducer<IndexModelState>;
    // 启用 immer 之后
    updateUser: ImmerReducer<IndexModelState>;
  };
  subscriptions: { setup: Subscription };
}

const UserModel: IndexModelType = {
  namespace: 'user',

  state: {
    userInfo: {}
  },

  effects: {
    *query({ payload }, { call, put }) {
    },
  },
  reducers: {
    // save(state, action) {
    //   return {
    //     ...state,
    //     ...action.payload,
    //   };
    // },
    // 启用 immer 之后
    updateUser(state, action) {
      console.log('action', action)
      state.userInfo = action.payload;
    }
  },
  subscriptions: {
    setup({ dispatch, history }) {}
  }
};

export default UserModel;